package com.sike.netty.jinjie.codec.protocol.encoder;

import com.alibaba.fastjson.JSONObject;
import com.sike.netty.jinjie.codec.protocol.message.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.util.List;

public class ObjectToJsonEncoder extends MessageToMessageEncoder<Message> {

    @Override
    protected void encode(ChannelHandlerContext ctx, Message msg, List out) throws Exception {
        if (msg != null) {
            out.add(JSONObject.toJSONString(msg));
        }
    }
}
